package com.sunagy.demand.front.controller;

import com.sunagy.demand.front.VO.ResultVO;
import com.sunagy.demand.front.dataobject.CustomerUserInfo;
import com.sunagy.demand.front.dto.CustomerUserInfoDto;
import com.sunagy.demand.front.service.CustomerUserInfoService;
import com.sunagy.demand.front.utils.BeanUtil;
import com.sunagy.demand.front.utils.ResultVOUtil;
import com.sunagy.demand.front.utils.UserContext;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * desc：客户信息接口
 * author：三餘無夢生
 * date：2018/4/11
 * time：下午4:10
 */
@Slf4j
@RestController
@RequestMapping("/customerUser")
@Api(value = "客户端用户", description = "用户信息相关接口")
public class CustomerUserController {

    @Autowired
    private CustomerUserInfoService customerUserInfoService;

    @ApiOperation(value = "查询客户信息", notes = "根据Token查询客户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "java.lang.String", name = "Authorization", value = "Token", required = false, paramType = "header")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public ResultVO<CustomerUserInfoDto> get() {
        CustomerUserInfo customerUserInfo = customerUserInfoService.getByCustomerUserId(UserContext.getUserID());
        CustomerUserInfoDto customerUserInfoDto = new CustomerUserInfoDto();
        BeanUtil.copyProperties(customerUserInfoDto,customerUserInfo);
        return ResultVOUtil.success(customerUserInfoDto);
    }

    @ApiOperation(value = "查询所有客户", notes = "根据Token查所有客户信息不分页")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "java.lang.String", name = "Authorization", value = "Token", required = false, paramType = "header")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ResultVO<List<CustomerUserInfoDto>> getAll() {
        List<CustomerUserInfoDto> customerUserInfoDtoList = (List<CustomerUserInfoDto>) BeanUtil.copyPropertiesList(customerUserInfoService.getAll(),CustomerUserInfoDto.class);
        return ResultVOUtil.success(customerUserInfoDtoList);
    }
}
